using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;



namespace KunURP
{
    public static class ShaderDrawUtility
    {
        private static Material s_SelectMaterial;
        private static Dictionary<string, bool> s_Group2IsOpenCache = new Dictionary<string, bool>();
        private static Dictionary<string, string> s_EnumKey2Group = new Dictionary<string, string>();

        public static void RefreshSelectMaterial()
        {
        }

        public static bool HaveGroup(string group)
        {
            return group != "" && group != "_";
        }

        public static bool CheckGroupIsShow(string group)
        {
            if (s_EnumKey2Group.ContainsKey(group))
            {
                string groupParent = s_EnumKey2Group[group];
                if (!s_Group2IsOpenCache.ContainsKey(groupParent) || !s_Group2IsOpenCache[groupParent])
                {
                    return false;
                }
            }
            if (s_Group2IsOpenCache.ContainsKey(group))
            {
                return s_Group2IsOpenCache[group];
            }
            return false;
        }

        public static void RefreshGroupIsOpen(string group, bool isShow)
        {
            s_Group2IsOpenCache[group] = isShow;
        }

        public static void RefreshEnumKey2Group(string enumKeyword, string group)
        {
            s_EnumKey2Group[enumKeyword] = group;
        }

        public static string GetShaderKeyword(string propName)
        {
            return propName.ToUpperInvariant() + "_ON";
        }

        public static void RefreshMaterialsKeywordEnabled(UnityEngine.Object[] materials, string keyword, bool enabled)
        {
            foreach (Material material in materials)
            {
                if (enabled)
                {
                    if (!material.IsKeywordEnabled(keyword))
                    {
                        material.EnableKeyword(keyword);
                    }
                }
                else
                {
                    if (material.IsKeywordEnabled(keyword))
                    {
                        material.DisableKeyword(keyword);
                    }
                }
            }
        }
    }
}